package com.lottery.ruok.lottrey.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.retrofitModule.response.SendRedPacketLogResponse;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ASUS on 2017/11/1.
 */

public class SendRedPacketAdapter extends BaseAdapter {
    private Context mContext;
    private SendRedPacketLogResponse getRedPacketLogResponses;

    public SendRedPacketAdapter(Context context, SendRedPacketLogResponse getRedPacketLogResponses) {
        mContext = context;
        this.getRedPacketLogResponses = getRedPacketLogResponses;
    }

    @Override
    public int getCount() {
        if (getRedPacketLogResponses == null) {
            return 0;
        }
        return getRedPacketLogResponses.getList().getGifts().size();
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view != null) {
            holder = (ViewHolder) view.getTag();
        } else {
            view = LayoutInflater.from(mContext).inflate(R.layout.send_packet_child_item, viewGroup, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }

        if(getRedPacketLogResponses.getList().getGifts().get(i).getType().equals("1")){
            holder.name.setText("点对点红包");
        } else  if(getRedPacketLogResponses.getList().getGifts().get(i).getType().equals("2")){
            holder.name.setText("普通红包");
        }   else {
            holder.name.setText("拼手气红包");
        }
        holder.time.setText(getRedPacketLogResponses.getList().getGifts().get(i).getCreated_at());
        holder.money.setText( getRedPacketLogResponses.getList().getGifts().get(i).getAmount());
        switch (getRedPacketLogResponses.getList().getGifts().get(i).getStatus()) {
            case "0":
                holder.result.setText("已领完  " + getRedPacketLogResponses.getList().getGifts().get(i).getGrabed() + "/" + getRedPacketLogResponses.getList().getGifts().get(i).getTotal() + "个");
                break;
            case "1":
                holder.result.setText("进行中  " + getRedPacketLogResponses.getList().getGifts().get(i).getGrabed() + "/" + getRedPacketLogResponses.getList().getGifts().get(i).getTotal() + "个");
                break;
            case "2":
                holder.result.setText("已过期  " + getRedPacketLogResponses.getList().getGifts().get(i).getGrabed() + "/" + getRedPacketLogResponses.getList().getGifts().get(i).getTotal() + "个");
                break;
        }

        return view;
    }

    static class ViewHolder {
        @BindView(R.id.name)
        TextView name;
        @BindView(R.id.time)
        TextView time;
        @BindView(R.id.money)
        TextView money;
        @BindView(R.id.result)
        TextView result;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
